package com.fyzk.activity.lottery.jc.football.newJz.data;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 16/5/2.
 */
public class RankingAdapter extends BaseAdapter {

    private Context context;
    private List<JCZQ_RankingResponse.DataBean> infos = new ArrayList<>();

    public RankingAdapter (Context context, List<JCZQ_RankingResponse.DataBean> infos){
        this.context = context;
        this.infos = infos;
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Object getItem(int i) {
        return infos.get(i);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder;
        JCZQ_RankingResponse.DataBean info = infos.get(i);
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.jc_ranking_item, null);
            holder.ranking_tv1 = (TextView) view.findViewById(R.id.jczq_ranking_tv1);
            holder.ranking_tv2 = (TextView) view.findViewById(R.id.jczq_ranking_tv2);
            holder.ranking_tv3 = (TextView) view.findViewById(R.id.jczq_ranking_tv3);
            holder.ranking_tv4 = (TextView) view.findViewById(R.id.jczq_ranking_tv4);
            holder.ranking_tv5 = (TextView) view.findViewById(R.id.jczq_ranking_tv5);
            holder.ranking_tv6 = (TextView) view.findViewById(R.id.jczq_ranking_tv6);
            holder.ranking_tv7 = (TextView) view.findViewById(R.id.jczq_ranking_tv7);
            holder.ranking_tv8 = (TextView) view.findViewById(R.id.jczq_ranking_tv8);
            holder.ranking_tv9 = (TextView) view.findViewById(R.id.jczq_ranking_tv9);
            holder.ranking_tv10 = (TextView) view.findViewById(R.id.jczq_ranking_tv10);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.ranking_tv1.setText(info.getRanking());
        holder.ranking_tv2.setText(info.getTeamName());
        holder.ranking_tv3.setText(info.getMatchCount());
        holder.ranking_tv4.setText(info.getWinCount());
        holder.ranking_tv5.setText(info.getDrawCount());
        holder.ranking_tv6.setText(info.getLossCount());
        holder.ranking_tv7.setText(info.getGoalBall());
        holder.ranking_tv8.setText(info.getLossBall());

        int jingBall = 0;
        try {
            jingBall = Integer.parseInt(info.getGoalBall()) - Integer.parseInt(info.getLossBall());
        } catch (Exception e) {

        }
        holder.ranking_tv9.setText(jingBall+"");
        holder.ranking_tv10.setText(info.getIntegral());

        try {
            if (info.getTeamName().equals(ScoreDetailActivity.matchInfoResponse.getHomeTeam())
                    || info.getTeamName().equals(ScoreDetailActivity.matchInfoResponse.getAwayTeam())) {
                view.setBackgroundColor(context.getResources().getColor(R.color.jczq_analysis_yellow));
            } else {
                view.setBackgroundColor(context.getResources().getColor(R.color.touming));

            }
        } catch (Exception e){

        }


        return view;
    }

    public void setInfos(List<JCZQ_RankingResponse.DataBean> infos){
        this.infos = infos;
        this.notifyDataSetChanged();
    }

    class ViewHolder {
        TextView ranking_tv1;
        TextView ranking_tv2;
        TextView ranking_tv3;
        TextView ranking_tv4;
        TextView ranking_tv5;
        TextView ranking_tv6;
        TextView ranking_tv7;
        TextView ranking_tv8;
        TextView ranking_tv9;
        TextView ranking_tv10;
    }

}
